import org.test.PriceAssessment
import org.test.Product

class BootStrap {

    def init = { servletContext ->
		
		environments {
			production {
				loadData()
			}
			development {
				loadData()
			}
		}
    }
	
	def loadData() {
		if (Product.count > 0){
			return
		}
		def vegetableOil = new Product(barcode: '0000001', description: 'CABBAGE VEGETABLE OIL')
		vegetableOil.save();
		
		def vegetableOilPrices = [
			new PriceAssessment(product: vegetableOil, price: 4.6, store: 'Local Store in ABQ', notes: 'On Sale'),
			new PriceAssessment(product: vegetableOil, price: 5.6, store: 'Walmart in ABQ', notes: ''),
			new PriceAssessment(product: vegetableOil, price: 6.9, store: 'FairPrice online store', notes: '2 x 1'),
			new PriceAssessment(product: vegetableOil, price: 3.9, store: 'FairPrice online store', notes: ''),
			new PriceAssessment(product: vegetableOil, price: 2.9, store: 'Small Store uptown in ABQ', notes: '')]
		
		for (price in vegetableOilPrices) {
			price.save()
		}
		
		def noodles = new Product(barcode: '0000002', description: 'SUN BRAND EGG NOODLES')
		noodles.save();
		
		def noodlesPrices = [
			new PriceAssessment(product: noodles, price: 1.6, store: 'Local Store in ABQ', notes: 'On Sale'),
			new PriceAssessment(product: noodles, price: 1.4, store: 'Walmart in ABQ', notes: ''),
			new PriceAssessment(product: noodles, price: 3.0, store: 'FairPrice online store', notes: '2 x 1'),
			new PriceAssessment(product: noodles, price: 1.9, store: 'FairPrice online store', notes: ''),
			new PriceAssessment(product: noodles, price: 0.9, store: 'Small Store uptown in ABQ', notes: '')]
		
		for (price in noodlesPrices) {
			price.save()
		}
		
		def cereal = new Product(barcode: '0000003', description: 'HARVEST FIELDS GOLDEN CORNFLAKES')
		cereal.save();
		
		def cerealPrices = [
			new PriceAssessment(product: cereal, price: 9.4, store: 'FairPrice online', notes: '2 x 1'),
			new PriceAssessment(product: cereal, price: 3.4, store: 'FairPrice online', notes: '')]
		
		for (price in cerealPrices) {
			price.save()
		}
	}

    def destroy = {
    }
}
